package models.dao;

import java.sql.ResultSet;

import model.pojo.Employee;
import models.util.MySqlDataAccessHelper;

public class EmployeeDAO {
	public static Employee getEmployee(String id,String database){
		Employee em = null;
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		String sql = "SELECT IDEmployee,FullName,UserName,IDDepartment,Position FROM employee WHERE IDEmployee ='" +id+"'";
		try {
			mysql.open(database);
			ResultSet rs = mysql.executeQuery(sql);
			rs.next();
			em = new Employee(rs.getString("IDEmployee"), rs.getString("FullName"),rs.getString("UserName"),rs.getInt("IDDepartment"),rs.getString("Position"));
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return em;
	}
	
	public static String getNameEmpByID(String id,String database){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();	
		String name="";
		String sql="select employee.FullName from employee where employee.IDEmployee='"+id+"'";
		try {
			mysql.open(database);
			ResultSet rs = mysql.executeQuery(sql);
			if (rs.next()) {	
				name=rs.getString("FullName");				
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				mysql.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return name;
	}
}